/** 
 * @author Huang RuiGuang
 * @date 2008/12/1
 *
 * Herm library
 * Copyright (c) 2008 by Huang RuiGuang(daemon.huang@gmail.com)
 *
 * Permission to use, copy, modify, distribute and sell this software.
 */

#ifndef HERM_FRAMEWORK_UDP_SESSION_H
#define HERM_FRAMEWORK_UDP_SESSION_H

#include "herm/base/network/interface.h"

class UDPPeer;
class UDPSession : public herm::ISession
{
public:
	UDPSession();
	virtual ~UDPSession();

	void Init(UDPPeer* peer, int index);
	void Reset(const herm::Address& remoteAddr);
	void Receive(const char* buf, int len);
	void SetStateCode(int stateType);
	virtual const herm::Address& GetLocalAddr() const;
	virtual const herm::Address& GetRemoteAddr() const;
private:
	virtual int GetIndex();
	virtual void RegisterHandler(herm::IMsgHandler* handler){(void)handler;}
	virtual herm::IMsgHandler* GetHandler() const{return nullptr;}
	virtual int Fetch(char* buf, int& len) const;
	virtual int Push(const char* buf, int len);
    virtual bool IsSendBufferEmpty() const{return false;}
    virtual herm::IPeer* GetPeer();
    virtual const herm::IPeer* GetPeer() const;
private:
	UDPPeer* m_peer;
	herm::uint32_t m_recvBytes;
	herm::uint32_t m_sendBytes;
	herm::uint32_t m_index;
	herm::Address m_remoteAddr;
	herm::uint32_t m_state;
};

#endif
